package com.ylzx.controller;

import com.ylzx.exception.BusinessException;
import com.ylzx.exception.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//全站异常处理类
@RestControllerAdvice
public class ProjectExceptionAdvice {

    @ExceptionHandler(SystemException.class)
    public Result doSystemExceptionHander(SystemException ex){
        return new Result(Code.SYSTEM_ERR, "0不能被除", null);
    }

    @ExceptionHandler(BusinessException.class)
    public Result doBusinessExceptionHander(BusinessException ex){
        return new Result(Code.SYSTEM_ERR, "您输入的编号不合法，请重新输入", null);
    }

    //捕获Exception异常：只要出现了任何Exception，都会触发下面的方法
    @ExceptionHandler(Exception.class)
    public Result doExceptionHander(Exception ex){
        return new Result(Code.GET_ERR, "其它异常", null);
    }


}
